<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>使所有区间的异或结果为零</title>
</head>
<body>
  <script>
    function fn(nums, k) {
      let m = 2000, n = 2 ** 10, dp = new Array(n).fill(m)
      dp[0] = 0
      for (let i = 0; i < k; i++) {
        let l = 0, h = new Map(), t = new Array(n)
        for (let j = i; j < nums.length; j += k) {
          h.has(nums[j]) ? h.set(nums[j], h.get(nums[j]) + 1) : h.set(nums[j], 1), l++
          t.fill(Math.min(...dp) + l)
        }
        for (let k = 0; k < n; k++) {
          for (let p of h) {
            t[k] = Math.min(t[k], dp[k ^ p[0]] + l - p[1])
          }
          dp = t.slice()
        }
      }
      return dp[0]
    }
    console.log(fn([1, 2, 0, 3, 0], 1));
  </script>
</body>
</html>